package com.thssh.ui.lsn14;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.thssh.ui.R;
import com.thssh.ui.lsn14.ext.BaseAdapter;
import com.thssh.ui.lsn14.view.SimpleListView;

import org.w3c.dom.Text;

import java.util.ArrayList;
import java.util.List;

public class Lsn14Activity extends AppCompatActivity {

    private SimpleListView simpleListView;
    private List<String> mDatas;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lsn14);
        simpleListView = (SimpleListView) findViewById(R.id.simple_list_view);
        mDatas = new ArrayList<>();
        for (int i = 0; i < 50; i++) {
            mDatas.add("data-" + i);
        }
        simpleListView.setAdapter(mAdapter);

    }

    class ViewHolder{
        public TextView tv;
    }

    private BaseAdapter mAdapter = new BaseAdapter() {

        @Override
        public int getCount() {
            return mDatas.size();
        }

        @Override
        public int getTypeCount() {
            return 1;
        }

        @Override
        public Object getItem(int position) {
            return mDatas.get(position);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder = null;
            if(convertView == null){
                convertView = View.inflate(Lsn14Activity.this, R.layout.item_simple, null);
                holder = new ViewHolder();
                holder.tv = convertView.findViewById(R.id.tv);
                convertView.setTag(holder);

            }else{
                holder = (ViewHolder) convertView.getTag();
            }
            holder.tv.setText(mDatas.get(position));
            return convertView;
        }
    };
}
